package com.itheima.info.manager.service;

import com.itheima.info.manager.dao.TeacherDao;
import com.itheima.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    public boolean addTeacher(Teacher tea) {
        return teacherDao.addTeacher(tea);
    }

    public boolean isExist(String teaId) {
        Teacher[] tea = teacherDao.findAllTeacher();
        boolean flag = false;

        for (int i = 0; i < tea.length; i++) {
            Teacher t = tea[i];
            if (t != null && t.getId().equals(teaId)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Teacher[] findAllTeacher() {
        Teacher[] tea = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < tea.length; i++) {
            Teacher t = tea[i];
            if (t!=null){
                flag=true;
                break;
            }
        }

        if (flag){
            return tea;
        }else {
            return null;
        }
    }

    public void deleteTeacherById(String teaId) {
        teacherDao.deleteTeacherById(teaId);
    }

    public void updateTeacher(String updateId, Teacher newTea) {
        teacherDao.updateTeacher(updateId,newTea);
    }
}
